﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using DataAnnotationsExtensions;

namespace JRFinances.ViewModels.VirtualTransactions
{
    public class CreateVirtualTransactionViewModel
    {
        public int CompanyId { get; set; }

        [Display(Name = "Data")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
        public DateTime Date { get; set; }

        [Display(Name = "Liczba")]
        [Min(1, ErrorMessage = "Liczba zakupionych akcji musi byc wieksza od 1")]
        public int Volume { get; set; }

        [Display(Name = "Cena")]
        [Min(0.01, ErrorMessage = "Cena zakupu musi byc wieksza od 0.01zl")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:F2}")]
        public double Price { get; set; }

        public bool Buy { get; set; }

        [Display(Name = "Obecne saldo")]
        public double CurrentSaldo { get; set; }

        public bool IsTransactionAmountValid()
        {
            if (CurrentSaldo >= Volume * Price)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}